home *** CD-ROM | disk | FTP | other *** search
/ A Teacher's Guide to the Holocaust / A Teacher's Guide to the Holocaust.iso / data / people / scripts / elemhotaclass.js < prev    next >
Text File  |  1999-12-05  |  4KB  |  145 lines

  1. // Copyright 1998,1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //Constructs a hot area element
  4. function MM_hota(theParent, theName, theInitialValue,
  5.                  theExpectedValue, theIsCorrect, theScore) {
  6.   // properties
  7.   this.initialValue = theInitialValue;
  8.   this.value = '';
  9.   this.disabled = false;
  10.  
  11.   this.expectedValue = theExpectedValue;
  12.   this.isCorrect = theIsCorrect;
  13.   this.score = theScore;
  14.   this.selected = false;
  15.  
  16.   this._parent = theParent;
  17.   this._name = theName;
  18.   this._self = theParent._self+".e['"+theName+"']";
  19.   this._obj = '';
  20.   
  21.   this.c = new Array(this); // NOTE: choice info stored on the element.
  22.  
  23.   // member functions
  24.   this.reset = MM_hotaReset;
  25.   this.init = MM_hotaInit;
  26.   this.initBackdrop = MM_hotaInitBackdrop;
  27.   this.enable = MM_hotaEnable;
  28.   this.disable = MM_hotaDisable;
  29.   this.setDisabled = MM_hotaSetDisabled;
  30.   this.update = MM_hotaUpdate;
  31.   this.validValue = MM_hotaValidValue;
  32.   this.changeValue = MM_hotaChangeValue;
  33.   this.setValue = MM_hotaSetValue;
  34.   this.setSelected = MM_hotaSetSelected;
  35.   
  36. }
  37.  
  38. //Resets the element
  39. function MM_hotaReset() {
  40.   var isChanged = '';
  41.   if (this._obj) with (this) {
  42.     isChanged = (value != initialValue);
  43.     value = initialValue;
  44.     disabled = _parent.disabled;
  45.     validValue();
  46.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  47.   }
  48. }
  49.  
  50. function MM_hotaInit() {
  51.   with (this) {
  52.     _obj = MM_intFindObject(_parent._self + _name); //find slider layer object
  53.     if (_obj)
  54.       MM_dragLayer(_parent._self + _name,'',0,0,0,0,false,false,0,0,0,0,false,false,0,_self + '.update()',true);
  55.     initBackdrop();
  56.   }
  57. }
  58.  
  59. function MM_hotaInitBackdrop() {
  60.   var theObj;
  61.   if (this._parent.bdInited == null) with (this) {
  62.     _parent.bdInited = true;
  63.     theObj = MM_intFindObject(_parent._self + "backdrop"); // find backdrop layer object
  64.     if (theObj) {
  65.       document.allLayers = null;
  66.       MM_dragLayer(_parent._self + "backdrop",'',0,0,0,0,false,false,0,0,0,0,false,false,0,
  67.                    "MM_hotaUpdateBackdrop(" + _parent._self + ")",true);
  68.   } }
  69. }
  70.  
  71. //Enables the element
  72. function MM_hotaEnable() {
  73.   if (this._obj) with (this) {
  74.     disabled = false;
  75.   }
  76. }
  77.  
  78. //Disables the element
  79. function MM_hotaDisable() {
  80.   this.disabled = true;
  81. }
  82.  
  83. //Calls the approppriate disable or enable function
  84. function MM_hotaSetDisabled(theDisabled) {
  85.   if (theDisabled) this.disable();
  86.   else this.enable();
  87. }
  88.  
  89. //Called by onClick event to update this elements value
  90. function MM_hotaUpdate() {
  91.   if (!this.disabled) with (this) {
  92.     changeValue((_parent.allowMultiSel) ? !value : true);
  93.     _parent.update();  // call the parent's update
  94.   }
  95. }
  96.  
  97. function MM_hotaValidValue() {
  98.   this.selected = (this.value == this.expectedValue);
  99.   return this.selected;
  100. }
  101.  
  102. function MM_hotaChangeValue(theValue) {
  103.   var i, isChanged = '', isReset = '';
  104.   with (this) {
  105.     isChanged = (value != theValue);
  106.     if (!_parent.allowMultiSel) {
  107.       value = theValue;
  108.       for (i in _parent.e) if (i != 'length') with (_parent) {
  109.         if (e[i] != this) {
  110.           isReset = (e[i].value != false);
  111.           e[i].value = false;
  112.         }
  113.         e[i].validValue();
  114.         if (e[i] != this && isReset && e[i].onChange != null) 
  115.           e[i].onChange(e[i]._parent._self+e[i]._name, e[i].value);
  116.       }
  117.     } else {
  118.       value = theValue;
  119.       validValue();
  120.     }
  121.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  122.   }
  123. }
  124.  
  125. function MM_hotaSetValue(theValue) {
  126.   with (this) {
  127.     changeValue(theValue);
  128.     _parent.update(true); // update int, but don't judge
  129.   }
  130. }
  131.  
  132. function MM_hotaSetSelected(theSelected) {
  133.   if (theSelected)
  134.     this.setValue(this.expectedValue);
  135.   else
  136.     this.setValue(!this.expectedValue);
  137. }
  138.  
  139. function MM_hotaUpdateBackdrop(theParent) {
  140.   if (!theParent.allowMultiSel) {
  141.     theParent.resetElems();
  142.     theParent.update();
  143.   }
  144. }
  145.